﻿using System;
using CrateMayhem.Common.Data;
using CrateMayhem.Common.Model;

namespace CrateMayhem.Common.Services
{
    public class GameService : IGameService
    {
        private readonly IWorldRepository worldRepository;
        public event EventHandler<PushEventArgs> Push;
        public event EventHandler<PushCompletedEventArgs> PushCompleted;
        public event EventHandler Finished;
        public event EventHandler Retry;
        public event EventHandler<PushEventArgs> Undo;

        public GameService(IWorldRepository worldRepository)
        {
            this.worldRepository = worldRepository;
        }

        public World Find(int level)
        {
            return worldRepository.Find(level);
        }

        public void RaisePush(MoveType move)
        {
            if (Push != null) Push(this, new PushEventArgs(move));
        }

        public void RaisePushCompleted(bool pushed, MoveType move)
        {
            if (PushCompleted != null) PushCompleted(this, new PushCompletedEventArgs(pushed, move));
        }

        public void RaiseFinished()
        {
            if (Finished != null) Finished(this, EventArgs.Empty);
        }

        public void RaiseRetry()
        {
            if (Retry != null) Retry(this, EventArgs.Empty);
        }

        public void RaiseUndo(MoveType move)
        {
            if (Undo != null) Undo(this, new PushEventArgs(move));
        }
    }
}